package com.sxs.controller;


import com.baomidou.mybatisplus.extension.api.ApiController;
import com.sxs.commonutils.R;
import com.sxs.entity.EduSubject;
import com.sxs.entity.vo.SubjectVO;
import com.sxs.service.EduSubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * 课程科目(EduSubject)表控制层
 *
 * @author makejava
 * @since 2021-09-27 16:49:38
 */
@Api(tags = "课程管理")
@RestController
@RequestMapping("/eduService/eduSubject")
@CrossOrigin
public class EduSubjectController extends ApiController {
    /**
     * 服务对象
     */
    @Resource
    private EduSubjectService eduSubjectService;

    /**
     * 查询所有数据
     *
     * @return 所有数据
     */
    @ApiOperation(value = "查询所有数据")
    @GetMapping("getAllSubject")
    public R selectAll() {
        List<SubjectVO> list = eduSubjectService.listWithTree();
        return R.ok().data("list",list);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation(value = "根据ID查询数据")
    @GetMapping("{id}")
    public R selectOne(@PathVariable String id) {
        EduSubject eduSubject=eduSubjectService.findById(id);
        return R.ok().data("eduSubject",eduSubject);
    }

    /**
     * 新增数据
     *
     * @param file 实体对象
     * @return 新增结果
     */
    @ApiOperation(value = "新增项目")
    @PostMapping("addSubject")
    public R insert(MultipartFile file) {
        System.out.println("上传文件");
        eduSubjectService.saveSubject(file,eduSubjectService);
        return R.ok();
    }

    /**
     * 修改数据
     *
     * @param eduSubject 实体对象
     * @return 修改结果
     */
    @PutMapping
    public R update(@RequestBody EduSubject eduSubject) {
        return R.ok();
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @DeleteMapping
    public R delete(@RequestParam("idList") List<Long> idList) {
        return R.ok();
    }
}
